Skip to content

fix(clerk-js): Trim emails, usernames and identifiers#2881

Merged
nikosdouvlis merged 1 commit into
mainfrom
george/sdk-1417-white-space-around-email-in-signin-results-in-error-no-trim
Feb 28, 2024
Merged

fix(clerk-js): Trim emails, usernames and identifiers#2881
nikosdouvlis merged 1 commit into
mainfrom
george/sdk-1417-white-space-around-email-in-signin-results-in-error-no-trim

Conversation

@desiprisg

@desiprisg desiprisg commented Feb 28, 2024

Copy link
Copy Markdown
Contributor

Description

Trim email addresses, usernames and the text identifier as whitespace at the start and end of the value is invalid.

To achieve the trimming for the identifier, a transformer prop has been added to useFormControl that can be used for other purposes as well.

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@changeset-bot

changeset-bot Bot commented Feb 28, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ddb455

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nikosdouvlis

Copy link
Copy Markdown
Member

@desiprisg please add a description and a changeset as this does change the behavior of the components

@desiprisg desiprisg force-pushed the george/sdk-1417-white-space-around-email-in-signin-results-in-error-no-trim branch from 2045d60 to 34bce6e Compare February 28, 2024 12:04
@desiprisg

Copy link
Copy Markdown
Contributor Author

!preview

@desiprisg desiprisg self-assigned this Feb 28, 2024
@clerk-cookie

clerk-cookie commented Feb 28, 2024

Copy link
Copy Markdown
Collaborator

Hey @desiprisg, your preview is available.

Status Preview Updated (UTC)
🍪 Deployed Visit preview Feb 28, 2024 12:10 PM

options: [],
defaultChecked: false,
};
const transformer: NonNullable<typeof options.transformer> = options.transformer ? options.transformer : v => v;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃

Suggested change
const transformer: NonNullable<typeof options.transformer> = options.transformer ? options.transformer : v => v;
const transformer: NonNullable<typeof options.transformer> = options.transformer ?? v => v;

Comment on lines +79 to +84
let value = rest.value;
let typeProps: Record<string, unknown> = { type };
if (typeof value === 'string' && type === 'email') {
value = value.trim();
typeProps = { pattern: '^.*@[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-\\.]+$' };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Is it possible to have type='email' but not a value that is a string ?
  2. I'd expect with the changes made in our useFormControl hook (below) that we wouldn't need to call value = value.trim(); manually here. Am i missing something ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed typescript here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the second question. Shouldn't there be a transformer in packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx for emailAddress?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a default transformer applied for type email in useFormControl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks good now

@desiprisg desiprisg force-pushed the george/sdk-1417-white-space-around-email-in-signin-results-in-error-no-trim branch from 34bce6e to 1ddb455 Compare February 28, 2024 13:38
Comment thread packages/clerk-js/src/ui/utils/useFormControl.ts
@nikosdouvlis nikosdouvlis merged commit 7904096 into main Feb 28, 2024
@nikosdouvlis nikosdouvlis deleted the george/sdk-1417-white-space-around-email-in-signin-results-in-error-no-trim branch February 28, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants